package com.playball.lottery.frm.buyhall;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.MyDialog;
import com.playball.lottery.customview.NewDelButtonAdapter;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.buyhall.ElvSelFiveListActivity.AsyncLoader;
import com.playball.lottery.frm.yhzx.BetProtocolActivity;
import com.playball.lottery.frm.yhzx.JddRechargeListActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.Constants;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.DynArrayInt;
import com.playball.lottery.util.GetIDAsyncLoader;
import com.playball.lottery.util.LotConstants;
import com.playball.lottery.util.MyPreference;
import com.playball.lottery.util.New11x5Util;
import com.playball.lottery.util.PreferencesUtils;
import com.playball.lottery.util.SysApplication;


/**
 * 11运夺金选号列表界面
 * 
 * @author Administrator
 * 
 */
public class ElvYunDJListActivity extends ListActivity implements DefConstants {
	/** Called when the activity is first created. */

	private LinearLayout btnAddRandom;
	private LinearLayout btnBack;
	private LinearLayout btnClear;
	// private Button btnPlus;
	// private Button btnMinus;
	private Button btnBuy;

	// private TextView bsText;
	private EditText buy_11x5xhlb_EditText01;
	// private TextView sumBsText;
	// private TextView countText;
	private TextView moneyText;

	View buy_elvxhlb_linearlayout01;
	View buy_elvxhlb_linearlayout02;

	private int buy_icon;

	private int playTypeId;
	private int bs = 1;
	private int zh = 1;
	private int allMoney;
	private int lotID;
	// private String vouchersNo;// 折扣编号
	// private double canDeductMoney;// 折扣金额
	private String issueID;
	private String issueName;
	private String randomBall;

	private DynArrayInt ball_1st_dintInt;
	private DynArrayInt ball_2nd_dintInt;
	private DynArrayInt ball_3rd_dintInt;
	private DynArrayInt money_dintInt;

	private ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
	// private ApplicationBall app_11x5dto;// 全局变量
	LinearLayout foot_layout;
	TextView tv_bet_protocol;
	CheckBox cb_bet_protocol;

	private String[] dyn;
	private LinearLayout buy_11x5;
	private LinearLayout gpc_hide;
	private CheckBox iszhuihao;
	private EditText zhuihao_EditText;
	private Context context;
	private PreferencesUtils pUtil;

	// 智能追号按钮
	private Button btnIntelligenceChase;
	// 目前只支持单个
	private ArrayList<HashMap<String, Object>> listIntelligenceChase;
	private int prizeIntellChase;

	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			Bundle b = msg.getData();
			issueID = b.getString("issueID");
			issueName = b.getString("issueName");

		}
	};

	/** 发起合买 */
	Button btn_buy_xhlb_hemai;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.buy_11x5_list);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
						| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		SysApplication.getInstance().addActivity(this);
		context = this;
		pUtil = new PreferencesUtils(context, Constants.PREFERENCES_NAME);
		// app_11x5dto = (ApplicationBall) getApplication();
		// Log.v("ElvYunDJListActivity", "ElvYunDJListActivity onCreate");
		// 初始化
		initView();
		buy_11x5 = (LinearLayout) findViewById(R.id.buy_11x5);
		LayoutInflater inflater = LayoutInflater.from(this);
		foot_layout = (LinearLayout) inflater.inflate(
				R.layout.bet_protocol_foot, null);
		tv_bet_protocol = (TextView) foot_layout
				.findViewById(R.id.bet_protocol);
		cb_bet_protocol = (CheckBox) foot_layout
				.findViewById(R.id.bet_protocol_choice);
//		tv_bet_protocol.setText(Html.fromHtml("<u>我已满18周岁并同意《服务条款》"));
		tv_bet_protocol.setVisibility(View.VISIBLE);//显示服务协议
		cb_bet_protocol.setChecked(true);
		tv_bet_protocol.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(ElvYunDJListActivity.this,
						BetProtocolActivity.class), 0);
			}
		});
		this.getListView().addFooterView(foot_layout);
		buy_11x5xhlb_EditText01 = (EditText) findViewById(R.id.buy_11x5xhlb_EditText01);
		// 倍数的焦点事件
		buy_11x5xhlb_EditText01.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
					gpc_hide.setVisibility(View.GONE);
				}

			}
		});
		buy_11x5xhlb_EditText01.addTextChangedListener(textWatcher);
		// 获得传来的数组，并放入ListView
		Intent intent = getIntent();
		playTypeId = intent.getIntExtra("PlayTypeID", 0);
		allMoney = intent.getIntExtra("AllMoney", 0);
		issueID = intent.getStringExtra("IssueID");
		issueName = intent.getStringExtra("IssueName");
		lotID = intent.getIntExtra("LotID", LOT_ID_11YDJ);
		bs = intent.getIntExtra("bs", 1);
		prizeIntellChase = intent.getIntExtra("prizeIntellChase", 0);

		moneyText.setText(allMoney + "");
		if (issueID == null || issueName == null) {
			GetIDAsyncLoader task = new GetIDAsyncLoader(this, handler, lotID);
			String[] parms = new String[2];
			parms[0] = "200";
			JSONObject jsob = new JSONObject();
			try {
				// 设置请求所需参数
				jsob.put("LottID", lotID);
			} catch (JSONException ex) {
				// TODO Auto-generated catch block
				Log.e("error", ex.toString());
			}
			parms[1] = jsob.toString();
			task.execute(parms);
		}
		@SuppressWarnings("unchecked")
		List<BallDTO> arrayList = (ArrayList<BallDTO>) intent
				.getSerializableExtra("list_elvdto");
		for (BallDTO elvdto : arrayList) {
			String elv_ball = elvdto.getElv_ball();
			list = getData(elv_ball);
		}
		initSimpleAdapter(list);

		// 继续添加号码
		btnBack.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.putExtra("playTypeId", playTypeId);
				intent.putExtra("ifbacklist", true);
				intent.putExtra("prizeIntellChase", prizeIntellChase);
				intent.putExtra("bs", bs);
				intent.setClass(context, ElvYunDJActivity.class);
				startActivity(intent);
				finish();
			}
		});

		// 清空列表按钮
		btnClear.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ApplicationData.getInstance().getList_11x5dto().size() > 0) {
					// AlertDialog.Builder dialog = new
					// AlertDialog.Builder(ElvYunDJListActivity.this);
					// dialog.setTitle("清空号码提示");
					// dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
					// dialog.setIcon(R.drawable.yhzx_main_warn);
					// dialog.setPositiveButton("确定", new
					// DialogInterface.OnClickListener() {
					// @Override
					// public void onClick(DialogInterface dialog, int which) {
					// // 获得自定义的应用程序BallDTO,初始化
					// list = new ArrayList<HashMap<String, Object>>();
					// ApplicationData.getInstance().initList();
					// // 金额清零
					// allMoney = 0;
					// setNoMsg();
					// buy_elvxhlb_linearlayout01.setVisibility(View.GONE);
					// buy_elvxhlb_linearlayout02.setVisibility(View.VISIBLE);
					// initText();
					// }
					// });
					// dialog.setNegativeButton("取消", new
					// DialogInterface.OnClickListener() {
					// @Override
					// public void onClick(DialogInterface dialog, int which) {
					// dialog.cancel();
					// }
					// }).create();
					// dialog.show();

					MyDialog.Builder dialog = new MyDialog.Builder(
							ElvYunDJListActivity.this);
					dialog.setTitle("清空号码提示");
					dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
					dialog.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									// 获得自定义的应用程序BallDTO,初始化
									list = new ArrayList<HashMap<String, Object>>();
									ApplicationData.getInstance().initList();
									zhuihao_EditText.setText("1");
									bs = 1;
									/*
									 * 追号需要修改的地方
									 */
									zh = 1;
									// 金额清零
									allMoney = 0;
									setNoMsg();
									buy_elvxhlb_linearlayout01
											.setVisibility(View.GONE);
									buy_elvxhlb_linearlayout02
											.setVisibility(View.VISIBLE);
									initText();
									dialog.cancel();
								}
							});
					dialog.setNegativeButton("取消",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.cancel();
								}
							}).create().show();
				}
			}
		});

		// 添加随机号码
		btnAddRandom.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				buy_elvxhlb_linearlayout01.setVisibility(View.VISIBLE);
				buy_elvxhlb_linearlayout02.setVisibility(View.GONE);
				randomBall = "";
				if (playTypeId == 6210) {
					randomDirectThree();
					// System.out.println("ball__ = " + randomBall);
				} else if (playTypeId == 6209) {
					randomDirectTwo();
				} else {
					// 按玩法随机球
					int ball_random[] = RandomGenData(1, 11,
							getRandomNum(playTypeId));

					// 随机生成的号码添加到dintInt
					ball_1st_dintInt = new DynArrayInt();
					ball_1st_dintInt.addInt(ball_random);

					// 在这个Activity每选中一注球，所有号码全部存储到xxx_dintInt int[]数组中
					randomBall = ball_1st_dintInt
							.getAllIntToString(ball_1st_dintInt.getAllInt());
					randomBall = randomBall.substring(0,
							randomBall.length() - 1);
				}
				// 实例化一个新的BallDTO放入到全局变量ApplicationBall中的List_elv里

				BallDTO elvdto = new BallDTO();
				elvdto.setElv_ball(randomBall + "-" + 2);
				// 获得自定义的应用程序BallDTO
				// 将我们放到进程中的全局变量拿出来，看是不是我们曾经设置的值
				// Log.i("application_11x5", "InitLabel:application_11x5_sel:" +
				// app_11x5dto.getList_11x5dto().size());
				// 新选的号码，追加在ApplicationBall全局变量list_ssqdto里
				ApplicationData.getInstance().getList_11x5dto().add(elvdto);
				allMoney += 2;
				ApplicationData.getInstance().setAll_11x5money(allMoney);
				ApplicationData.getInstance().setPlay_11x5Id(playTypeId);
				moneyText.setText(allMoney + "");
				// System.out.println("ballInfact = " + randomBall);
				initSimpleAdapter(getData(randomBall + "-" + 2));
			}
		});

		// 增加倍数按钮
		// btnPlus.setOnClickListener(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// allMoney = ApplicationData.getInstance().getAll_11x5money();
		// if (buy_11x5xhlb_EditText01.getText().toString().equals("")) {
		// buy_11x5xhlb_EditText01.setText("1");
		// } else if (bs < 999) {
		// bs = Integer.parseInt(buy_11x5xhlb_EditText01.getText().toString());
		// bs++;
		// buy_11x5xhlb_EditText01.setText(bs + "");
		// sumBsText.setText(bs + "");
		// moneyText.setText(allMoney * bs + "");
		// } else {
		// buy_11x5xhlb_EditText01.setText("999");
		// // bs = 999;
		// }
		// }
		// });

		// 减少倍数按钮
		// btnMinus.setOnClickListener(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		//
		// allMoney = ApplicationData.getInstance().getAll_11x5money();
		// if (buy_11x5xhlb_EditText01.getText().toString().equals("")) {
		// buy_11x5xhlb_EditText01.setText("1");
		// } else if (bs < 2) {
		// bs = 1;
		// } else {
		// bs = Integer.parseInt(buy_11x5xhlb_EditText01.getText().toString());
		// bs--;
		// buy_11x5xhlb_EditText01.setText(bs + "");
		// sumBsText.setText(bs + "");
		// moneyText.setText(allMoney * bs + "");
		// }
		// }
		// });

		// 购买按钮
		btnBuy.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (ApplicationData.getInstance().isUserLogin()) {
					if (issueID == null || issueName == null) {
						Toast.makeText(context,
								R.string.the_network_is_not_to_force,
								Toast.LENGTH_SHORT).show();
						return;
					}
					if(bs * allMoney > 2000000){
						Toast.makeText(context, "单个方案的总金额必须在2元至2000000元之间", Toast.LENGTH_SHORT).show();
						return;
					}
					if (list.size() < 1) {
						Toast.makeText(ElvYunDJListActivity.this,
								R.string.betting_number_cannot_be_empty,
								Toast.LENGTH_SHORT).show();
					} /*
					 * else if
					 * (buy_11x5xhlb_EditText01.getText().toString().equals(""))
					 * { Toast.makeText(ElvYunDJListActivity.this,
					 * R.string.buy_at_least_one_times, Toast.LENGTH_SHORT)
					 * .show(); buy_11x5xhlb_EditText01.setText("1"); } else if
					 * (zhuihao_EditText.getText().toString().equals("")) {
					 * zhuihao_EditText.setText("1");
					 * Toast.makeText(ElvYunDJListActivity.this,
					 * R.string.period_of_time_can_not_be_empty,
					 * Toast.LENGTH_SHORT).show(); }
					 */else {

						if (cb_bet_protocol.isChecked() == false) {
							Toast.makeText(
									ElvYunDJListActivity.this,
									R.string.need_to_agree_to_just_can_continue_to_buy,
									Toast.LENGTH_SHORT).show();
							return;
						}
						/*
						 * 追号需要修改的地方
						 */
						if (zh == 1) {
							startBuyThread();
						} else {
							newZhuiHaoTthread();
						}
						/*
						 * MyDialog dialog = new
						 * MyDialog.Builder(ElvYunDJListActivity
						 * .this).setTitle("购买提示").setMessage("是否确认购买？")
						 * .setPositiveButton("确定", new
						 * DialogInterface.OnClickListener() { public void
						 * onClick(DialogInterface dialog, int which) { //
						 * startVouchersThread(); startBuyThread();
						 * dialog.cancel(); } }).setNegativeButton("取消", new
						 * DialogInterface.OnClickListener() {
						 * 
						 * @Override public void onClick(DialogInterface dialog,
						 * int which) { dialog.cancel(); } }).create();
						 * dialog.setCanceledOnTouchOutside(false);
						 * dialog.setCancelable(true);// 设置back键是否可以取消
						 * dialog.show();
						 */
					}
				} else {
					Intent intent = new Intent();
					intent.setClass(context, LoginActivity.class);
					startActivity(intent);
				}
			}
		});

		// 智能追号
		btnIntelligenceChase.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (listIntelligenceChase.size() == 1) {
					if (Constants.LIST_LOTNUM != null) {
						Constants.LIST_LOTNUM.clear();
					}
					String mulStr = listIntelligenceChase.get(0)
							.get("buy_11x5_list_money").toString();
					int mul = Integer.parseInt(mulStr) / 2;
					if (mul == 1) {
						Constants.LIST_LOTNUM.addAll(getLotNum());
						Intent intent = new Intent(ElvYunDJListActivity.this,
								IntelligenceChaseActivity.class);
						intent.putExtra("issueID", issueID);
						intent.putExtra("issueName", issueName);
						intent.putExtra("lotID", lotID);
						intent.putExtra("prizeIntellChase", prizeIntellChase);
						startActivityForResult(intent, 1001);
					} else {
						Toast.makeText(ElvYunDJListActivity.this, "目前只支持单注",
								Toast.LENGTH_LONG).show();
					}
				} else if (listIntelligenceChase.size() == 0) {
					Toast.makeText(ElvYunDJListActivity.this, "请选择一注",
							Toast.LENGTH_LONG).show();
				} else {
					Toast.makeText(ElvYunDJListActivity.this, "目前只支持单注",
							Toast.LENGTH_LONG).show();
				}

			}
		});

		buy_11x5.getViewTreeObserver().addOnGlobalLayoutListener(
				new OnGlobalLayoutListener() {

					@Override
					public void onGlobalLayout() {
						int heightDiff = buy_11x5.getRootView().getHeight()
								- buy_11x5.getHeight();
						// 判断焦点在哪里
						if (zhuihao_EditText.hasFocus()) {
							if (heightDiff > 100) {
								// 大小超过100时，一般为显示虚拟键盘事件
								gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
								if (zh > 1) {
									gpc_hide.setVisibility(View.VISIBLE);
								} else {
									gpc_hide.setVisibility(View.GONE);
								}
							} else {
								gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
								gpc_hide.setVisibility(View.GONE);
							}
						}

					}
				});
		buy_11x5xhlb_EditText01.setText(""+bs);
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	// 追号的EditText监听
	private TextWatcher zhuihaoWatcher = new TextWatcher() {
		private boolean isChanged = false;

		@Override
		public void afterTextChanged(Editable s) {
			if (isChanged) {
				return;
			}
			if (!zhuihao_EditText.getText().toString().equals("")) {
				zh = Integer.parseInt(s.toString());
				isChanged = true;
				String str2 = s.toString().trim().replaceFirst("^0*", "");// 正则去除
				if (zh < 1) {
					// Toast.makeText(ElvYunDJListActivity.this,
					// R.string.buy_at_least_one, Toast.LENGTH_SHORT).show();
					zhuihao_EditText.setText("1");
					zh = 1;
				} else if (zh > 50) {
					Toast.makeText(ElvYunDJListActivity.this, "最多追50期",
							Toast.LENGTH_SHORT).show();
					zhuihao_EditText.setText("50");
					zh = 50;
				} else {
					zhuihao_EditText.setText(str2);
				}
				zhuihao_EditText.setSelection(zhuihao_EditText.length());
				isChanged = false;
				zhuihao_EditText.invalidate();
			} else {
				zh = 1;
			}
			moneyText.setText(allMoney * zh * bs + "");
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
		}

	};

	private TextWatcher textWatcher = new TextWatcher() {
		private boolean isChanged = false;

		public void afterTextChanged(Editable s) {
			// TODO Auto-generated method stub
			if (isChanged) {
				return;
			}
			if (!buy_11x5xhlb_EditText01.getText().toString().equals("")) {

				bs = Integer.parseInt(s.toString());
				isChanged = true;
				String str2 = s.toString().trim().replaceFirst("^0*", "");// 正则去除
				if (bs < 1) {
					// Toast.makeText(ElvYunDJListActivity.this,
					// R.string.the_minimum_ratio_of_one,
					// Toast.LENGTH_SHORT).show();
					buy_11x5xhlb_EditText01.setText("1");
					bs = 1;
				} else if (bs > 999) {
					Toast.makeText(ElvYunDJListActivity.this,
							R.string.the_maximum_ratio_of_dig_3_nine,
							Toast.LENGTH_SHORT).show();
					buy_11x5xhlb_EditText01.setText("999");
					bs = 999;
				} else {
					buy_11x5xhlb_EditText01.setText(str2);
				}
				buy_11x5xhlb_EditText01.setSelection(buy_11x5xhlb_EditText01
						.length());
				isChanged = false;
				buy_11x5xhlb_EditText01.invalidate();
			} else {
				/*
				 * if (buy_11x5xhlb_EditText01.getText().toString().equals(""))
				 * { Toast.makeText(ElvYunDJListActivity.this,
				 * R.string.buy_at_least_one_times, Toast.LENGTH_SHORT) .show();
				 * 
				 * }
				 */
				bs = 1;
			}
			moneyText.setText(allMoney * zh * bs + "");
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
			// TODO Auto-generated method stub
			// Log.d("TAG", "beforeTextChanged--------------->");
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			// Log.d("TAG", "onTextChanged--------------->");
		}

	};

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		String action;
		ShowTipDialog showdialog = new ShowTipDialog();

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(ElvYunDJListActivity.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;

			action = paramsArr[1];
			// 获取请求返回值
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(paramsArr[0],
					UserID, action, getApplicationContext());
			// 获取请求返回值
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				// if (action.equals("203")) {
				// getVouchers(result);
				// }
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						if (action.equals("207")) {
							Buy(result);
						}else {
							Buy2(result);
						}
					}else {
						Toast.makeText(ElvYunDJListActivity.this, js.getString("Data"), Toast.LENGTH_LONG).show();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}finally {
					showdialog.closeDialog();
				}
			} else {
				Toast.makeText(ElvYunDJListActivity.this,
						getString(R.string.problem_01), Toast.LENGTH_LONG)
						.show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}
	/**
	 * 获取ChaseIsuses列表
	 */
	public String getIsuses() {
		List list=new ArrayList();
		int endNumber=(78-Integer.parseInt(issueName.substring(4,issueName.length())));
		int issueNumber=Integer.parseInt(issueName);
		try{
			List<Map<String, Object>> list_LotNum = new ArrayList<Map<String, Object>>();
			list_LotNum = getLotNum();
			// 设置请求所需参数
			JSONArray array1 = new JSONArray();
			for (int i = 0; i < list_LotNum.size(); i++) {
				JSONObject o = new JSONObject(list_LotNum.get(i));
				array1.put(o);
			}
			if (zh<endNumber){
				for (int i = 0; i <zh ; i++) {
					JSONObject map= new JSONObject();
					map.put("IsuseName",issueNumber);
					map.put("LotteryNumber",array1);
					map.put("Multiple",bs);
					map.put("Money",bs * allMoney);
					issueNumber++;
					list.add( map);
				}
			}else {
				Toast.makeText(ElvYunDJListActivity.this, "还有"+endNumber+"可以追", Toast.LENGTH_LONG).show();
			}
		}catch (Exception e){
			e.printStackTrace();
		}
		return list.toString();
	}
	// 新追号线程
	private void newZhuiHaoTthread(){

		AsyncLoader taskIssure = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			params.put("LottID", lotID);
			params.put("StopMoney",iszhuihao.isChecked() ? 1 : 0);
			params.put("ChaseIsuses", getIsuses());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		dyn[0] = params.toString();
		dyn[1] = "208";
		taskIssure.execute(dyn);
	}
	// 追号线程
	private void startZhuiHaoThread() {
		// 获取期号
		AsyncLoader taskIssure = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			params.put("LottID", lotID);
			params.put("ChaseCount", zh);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		dyn[0] = params.toString();
		dyn[1] = "2081";
		taskIssure.execute(dyn);
	}

	public void getIssue(String result) {
		List<String> list = new ArrayList<String>();
		try {
			JSONArray js = new JSONArray(result);
			for (int i = 0; i < js.length(); i++) {
				JSONObject json = new JSONObject(js.getString(i));
				list.add(json.getString("ID"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		List<Map<String, Object>> list_LotNum = new ArrayList<Map<String, Object>>();
		list_LotNum = getLotNum();

		AsyncLoader task = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			JSONArray array = new JSONArray();
			JSONArray array1 = new JSONArray();
			for (int i = 0; i < list_LotNum.size(); i++) {
				JSONObject o = new JSONObject(list_LotNum.get(i));
				array1.put(o);
			}
			for (int j = 0; j < zh; j++) {
				JSONObject json = new JSONObject();
				json.put("IssueID", list.get(j));
				json.put("LotteryNumber", array1);
				json.put("Multiple", bs);
				json.put("Money", bs * allMoney);
				array.put(json);
			}
			params.put("StopMoney", iszhuihao.isChecked() ? 1 : 0);
			params.put("SumNum", allMoney / 2);
			params.put("BuyMoney", bs * allMoney * zh);
			params.put("ChaseIsuses", array);
			params.put("LottID", lotID);
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();

		dyn[1] = "208";
		task.execute(dyn);

	}

	private void startBuyThread() {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		list = getLotNum();

		AsyncLoader task = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();

		try {
			// 设置请求所需参数
			JSONArray array1 = new JSONArray();
			for (int i = 0; i < list.size(); i++) {
				JSONObject o = new JSONObject(list.get(i));
				// System.out.println(o);
				array1.put(o);
			}
			params.put("SchemeType", 1);// 方案类型 1自购，2合买，3保存 1
			params.put("BetType", 1);// 投注类型 1选号投注 2单式上传 3先发后传 1
			params.put("BonusScale", 0);
			params.put("AssureShare", 0);
			params.put("Description", "");
			params.put("OpenUserList", "");
			params.put("SecrecyLevel", 4);
			params.put("BuyShare", bs * allMoney);
			params.put("Multiple", bs);
			params.put("LotteryID", lotID);
			params.put("IssueID", issueID);
			params.put("IssueName", issueName);
			params.put("Number", array1);
			params.put("Money", bs * allMoney);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();
		dyn[1] = "207";
		task.execute(dyn);
	}

	// public void getVouchers(String strResult) {
	// Map<String, Object> map = new HashMap<String, Object>();
	//
	// try {
	// JSONTokener jsonParser = new JSONTokener(strResult);
	// JSONObject js = (JSONObject) jsonParser.nextValue();
	// if (Integer.parseInt(js.getString("Code")) > 0) {
	// map = ConvertJsonToList.getMap(js.getString("Result"));
	// vouchersNo = map.get("VouchersNo").toString();
	// canDeductMoney = (double)
	// (map.get("CanDeductAmount").toString().equals("") ? 0.0 :
	// Double.parseDouble(map.get("CanDeductAmount").toString()));
	// } else {
	// }
	// } catch (JSONException e) {
	// // 异常处理代码
	// Log.e("error", e.toString());
	// }
	//
	// }

	/*
	 * 追号需要修改的地方
	 */
	public void Buy2(String strResult) {

		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			if (Integer.parseInt(js.getString("Code")) < 0) {
				buy_icon = R.drawable.buy_failure;
				String balanceNotFull = js.getString("Data");
				// String balance = "当前余额:"+
				// ApplicationData.getInstance().getUserMoney() +"元" +"\n";

				JSONObject params = new JSONObject();
				params.put("Multiple", bs);
				params.put("LotteryID", lotID);
				params.put("IssueName", issueName);
				params.put("Money", bs * allMoney * zh);
				/*if (js.getString("Data").contains(Constants.BALANCE_BUZU)) {
					Intent intent = new Intent();
					intent.setClass(context, JddRechargeListActivity.class);
					intent.putExtra("params", params.toString());
					startActivityForResult(intent, REQ_CODE_NO_MONEY_2_RECHARGE);
				}else{
					new ShowTipDialog().showBuyInfo(ElvYunDJListActivity.this,
							balanceNotFull, "购买失败", buy_icon, params.toString());
				}*/
				new ShowTipDialog().showBuyInfoZH(ElvYunDJListActivity.this,
						balanceNotFull, "购买失败", buy_icon, params.toString());


			} else {
				buy_icon = R.drawable.buy_success;

				String msg = "";

				System.err.println("期数：===" + zh);

				msg = "成功连续追号" + zh + "期\n\n我的认购：" + (allMoney * bs * zh)
						+ "元";//\n账户余额：" + js.getString("Msg").toString() + "元";

				if (!isFinishing()) {
					new ShowTipDialog().showBuyInfoZH(
							ElvYunDJListActivity.this, msg, "追号成功", buy_icon,
							dyn[0]);
					clearPUtil();
				}
				// 存贮数据
				MyPreference.getInstance(this).storeBLotID(
						LotConstants.LOT_ID_SSQ);
			}
		} catch (JSONException ex) {
			// 异常处理代码
			Log.e("error", ex.toString());
		}
	}

	public void Buy(String strResult) {
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			if (Integer.parseInt(js.getString("Code")) < 0) {
//				buy_icon = R.drawable.buy_failure;
//				if (js.getString("Data").contains(Constants.BALANCE_BUZU)) {
//					Intent intent = new Intent();
//					intent.setClass(context, JddRechargeListActivity.class);
//					intent.putExtra("params", dyn[0]);
//					startActivityForResult(intent, REQ_CODE_NO_MONEY_2_RECHARGE);
//				}else{
					new ShowTipDialog().showBuyInfo(ElvYunDJListActivity.this,
							js.getString("Data"), "购买失败", buy_icon, dyn[0]);
//				}
			} else {
				buy_icon = R.drawable.buy_success;
				String msg = "";
				if ("-1".equals(issueName)) {
					msg = "发起11运夺金 "
							+ "  购买方案\n\n我的认购："
							+ (allMoney * bs/*
											 * - canDeductMoney
											 */)
							/*+ "元\n账户余额："
							+ ConvertJsonToList.getMap(js.getString("Data"))
									.get("Balance").toString()/*
															 * getBalance ( )
															 */
							+ "元"+"\n方案编号："+js.getString("Data").toString();

				} else {
					msg = "发起11运夺金 "
							+ issueName
							+ "期购买方案\n\n我的认购："
							+ (allMoney * bs/*
											 * - canDeductMoney
											 */)
							/*+ "元\n账户余额："
							+ ConvertJsonToList.getMap(js.getString("Data"))
									.get("Balance").toString()/*
															 * getBalance ( )
															 */+ "元"+"\n方案编号："+js.getString("Data").toString();
				}
				new ShowTipDialog().showBuyInfo(ElvYunDJListActivity.this, msg,
						"投注成功", buy_icon, dyn[0]);
				clearPUtil();
				// 存贮数据
				MyPreference.getInstance(this).storeBLotID(
						LotConstants.LOT_ID_11YDJ);
			}
		} catch (JSONException e) {
			// 异常处理代码
			Log.e("error", e.toString());
		}
	}

	public String getBalance() {
		String money = "";
		String strResult = null;
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// 设置请求所需参数
			JSONObject params = new JSONObject();
			// 设置请求action
			String action = "107";// 108获取用户基本信息
			// 获取请求返回值
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(
					params.toString(), UserID, action, getApplicationContext());
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			map = ConvertJsonToList.getMap(js.getString("Data"));
			// money =
			// Float.parseFloat(map.get("Balance").toString().replaceAll(",",
			// "").trim());
			money = map.get("Balance").toString();
		} catch (Exception ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		return money;
	}

	/**
	 * 拼接投注号码
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getLotNum() {
		String lotNum = "";
		List<BallDTO> arrayList = ApplicationData.getInstance()
				.getList_11x5dto();
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (BallDTO elvdto : arrayList) {
			String elv_ball = elvdto.getElv_ball();
			elv_ball = elv_ball.substring(0, elv_ball.lastIndexOf("-"));
			// Log.e("getLotNum", "elv_ball= "+elv_ball.toString());
			if (playTypeId == 6210) {
				String nums[] = elv_ball.split("\\|");
				String first[] = nums[0].split(" ");
				String second[] = nums[1].split(" ");
				String third[] = nums[2].split(" ");
				for (String a : first) {
					for (String b : second) {
						if (!a.equals(b)) {
							for (String c : third) {
								if (!c.equals(b) && !c.equals(a)) {
									lotNum = lotNum + a + "|" + b + "|" + c
											+ "&";// lotNum
													// =
													// lotNum
													// +
													// a
													// +
													// "|"
													// +
													// b
													// +
													// "|"
													// +
													// c
													// +
													// "\n"
									// Log.v("getLotNum",
									// "lotNum1= "+lotNum.toString());
								}
							}
						}
					}
				}
			} else if (playTypeId == 6209) {
				String nums[] = elv_ball.split("\\|");
				String first[] = nums[0].split(" ");
				String second[] = nums[1].split(" ");
				for (String a : first) {
					for (String b : second) {
						if (!a.equals(b)) {
							lotNum = lotNum + a + "|" + b + "&";// lotNum =
																// lotNum + a +
																// "|" + b+ "\n"
						}
					}
				}
			} else {
				lotNum = elv_ball.replace(",", " ");// lotNum = lotNum +
													// elv_ball.replace(",",
													// " ")+ "\n"
				Map<String, Object> map = null;
				map = new HashMap<String, Object>();
				map.put("playid", playTypeId);
				map.put("number", lotNum);
				list.add(map);
			}
		}
		// Log.v("getLotNum", "lotNum--= "+lotNum.toString());
		// 处理拆分数据
		if (playTypeId == 6210 || playTypeId == 6209) {
			String number[] = (lotNum.substring(0, lotNum.length() - 1))
					.split("&");
			Map<String, Object> map = null;
			for (String num : number) {
				// Log.i("getLotNum", "num= "+num.toString());
				map = new HashMap<String, Object>();
				map.put("playid", playTypeId);
				map.put("number", num);
				list.add(map);
			}
		}
		// Log.e("getLotNum", "list= "+list.toString());
		return list;
	}

	public void randomDirectTwo() {
		int first_ball[] = RandomGenData(1, 11, 1);
		int second_ball[] = RandomGenData(1, 11, 1);
		// 判断是否有重复数字
		if (first_ball[0] == second_ball[0]) {
			randomDirectTwo();
		} else {
			ball_1st_dintInt = new DynArrayInt();
			ball_2nd_dintInt = new DynArrayInt();

			ball_1st_dintInt.addInt(first_ball);
			ball_2nd_dintInt.addInt(second_ball);
			String first = ball_1st_dintInt.getIntToString(0);
			String second = ball_2nd_dintInt.getIntToString(0);
			randomBall = first + "|" + second;
		}
	}

	public void randomDirectThree() {
		int first_ball[] = RandomGenData(1, 11, 1);
		int second_ball[] = RandomGenData(1, 11, 1);
		int third_ball[] = RandomGenData(1, 11, 1);
		// 判断是否有重复数字
		if (first_ball[0] == second_ball[0] || second_ball[0] == third_ball[0]
				|| third_ball[0] == first_ball[0]) {
			randomDirectThree();
		} else {
			ball_1st_dintInt = new DynArrayInt();
			ball_2nd_dintInt = new DynArrayInt();
			ball_3rd_dintInt = new DynArrayInt();

			ball_1st_dintInt.addInt(first_ball);
			ball_2nd_dintInt.addInt(second_ball);
			ball_3rd_dintInt.addInt(third_ball);

			String first = ball_1st_dintInt.getIntToString(0);
			String second = ball_2nd_dintInt.getIntToString(0);
			String third = ball_3rd_dintInt.getIntToString(0);
			randomBall = first + "|" + second + "|" + third;
			// System.out.println("ball = " + randomBall);
		}
	}

	// 随机取球，并显示
	public int[] RandomGenData(int min, int max, int num) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[num];
		List<Integer> a1 = new ArrayList<Integer>();

		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);
		}
		for (int i = 0; i < num; i++) {
			int index = rndNumber.nextInt(max - min + 1 - i);
			Object obj = a1.get(index);
			temp[i] = ((Integer) obj).intValue();
			a1.remove(index);
		}
		Arrays.sort(temp);
		return temp;
	}

	// 设置无记录
	public void setNoMsg() {
		List<Map<String, Object>> dataNull = new ArrayList<Map<String, Object>>();
		Map<String, Object> valueMap = new HashMap<String, Object>();
		valueMap.put("Message", "无记录");
		dataNull.add(valueMap);
		SimpleAdapter noMsgAdapter = new SimpleAdapter(
				ElvYunDJListActivity.this, dataNull,
				R.layout.buy_new11x5_listnum, new String[] { "Message" },
				new int[] { R.id.buy_11x5_list_ball });
		setListAdapter(noMsgAdapter);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void initSimpleAdapter(ArrayList list) {
		listIntelligenceChase = list;
		// Log.v("ElvYunDJListActivity",
		// "ElvYunDJListActivity before initSimpleAdapter ");
		// DelButtonAdapter listAdapter = new
		// DelButtonAdapter(ElvYunDJListActivity.this, list,
		// R.layout.buy_11x5_listnum, new String[] { "buy_11x5_list_ball",
		// "buy_11x5_list_money", "buy_11x5_list_delete" }, new int[] {
		// R.id.buy_11x5_list_ball, R.id.buy_11x5_list_money,
		// R.id.buy_11x5_list_delete });
		NewDelButtonAdapter listAdapter = new NewDelButtonAdapter(
				ElvYunDJListActivity.this, list, R.layout.buy_new11x5_listnum,
				new String[] { "buy_11x5_list_ball", "buy_11x5_list_money",
						"buy_11x5_list_delete", "buy_11x5_list_playtype" },
				new int[] { R.id.buy_11x5_list_ball,
						R.id.buy_new11x5_list_zhumoney,
						R.id.buy_11x5_list_delete,
						R.id.buy_new11x5_list_playtype });
		// Log.v("ElvYunDJListActivity",
		// "ElvYunDJListActivity onCreate initSimpleAdapter");
		if (listAdapter.GetElvList().size() > 0) {
			list = new ArrayList<HashMap<String, Object>>();
			money_dintInt = new DynArrayInt();
			Iterator<BallDTO> it = ApplicationData.getInstance()
					.getList_11x5dto().iterator();
			for (; it.hasNext();) {
				it.next();
				it.remove();
			}
			for (BallDTO elvdto : listAdapter.GetElvList()) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				String[] ballString = elvdto.getElv_ball().toString()
						.split("-");
				map.put("buy_11x5_list_ball",
						ballString[0].toString().replace(",", " "));
				map.put("buy_11x5_list_money", ballString[1].toString());
				map.put("buy_11x5_list_delete", R.drawable.default_delbtn02);
				list.add(map);

				elvdto = new BallDTO();
				elvdto.setElv_ball(ballString[0].toString().replace(",", " ")
						+ "-" + ballString[1].toString());

				ApplicationData.getInstance().getList_11x5dto().add(elvdto);

				// 通过传来的单注金额，保存在money_dintInt数组里,计算出总金额
				money_dintInt.addInt(Integer.parseInt(ballString[1]));
				FactoryAllResult();
			}
			setListAdapter(listAdapter);
		} else {

			allMoney = 0;
			// playTypeId = 7001;
			bs = 1;
			initText();
			// 获得自定义的应用程序BallDTO,初始化
			ApplicationData.getInstance().initList();
			setNoMsg();
			buy_elvxhlb_linearlayout01.setVisibility(View.GONE);
			buy_elvxhlb_linearlayout02.setVisibility(View.VISIBLE);
		}

	}

	private ArrayList<HashMap<String, Object>> getData(String elv_ball) {
		if (!elv_ball.equals("")) {
			String[] ballString = elv_ball.split("-");
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("buy_11x5_list_ball",
					ballString[0].toString().replace(",", " "));
			map.put("buy_11x5_list_money", ballString[1].toString());
			map.put("buy_11x5_list_delete", R.drawable.default_delbtn02);
			// 玩法
			map.put("buy_11x5_list_playtype",
					New11x5Util.getNew11ydjPlayType(playTypeId));
			list.add(map);
		}
		return list;
	}

	private int getRandomNum(int typeId) {
		int num = 0;
		switch (typeId) {
		case 6201:
			num = 1;
			break;
		case 6202:
		case 6211:
			num = 2;
			break;
		case 6203:
		case 6212:
			num = 3;
			break;
		case 6204:
			num = 4;
			break;
		case 6205:
			num = 5;
			break;
		case 6206:
			num = 6;
			break;
		case 6207:
			num = 7;
			break;
		case 6208:
			num = 8;
			break;
		}
		return num;
	}

	public void initView() {

		buy_elvxhlb_linearlayout01 = findViewById(R.id.buy_elvxhlb_linearlayout01);
		buy_elvxhlb_linearlayout02 = findViewById(R.id.buy_elvxhlb_linearlayout02);

		
		btn_buy_xhlb_hemai = (Button) findViewById(R.id.btn_buy_xhlb_hemai);
		// 发起合买
		btn_buy_xhlb_hemai.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (ApplicationData.getInstance().isUserLogin()) {
					if (issueID == null || issueName == null) {
						Toast.makeText(context, R.string.the_network_is_not_to_force,Toast.LENGTH_SHORT).show();
						return;
					}
					if (list.size() < 1) {
						Toast.makeText(ElvYunDJListActivity.this,R.string.betting_number_cannot_be_empty, Toast.LENGTH_SHORT).show();
					} else {
						if (cb_bet_protocol.isChecked() == false) {
							Toast.makeText(ElvYunDJListActivity.this,R.string.need_to_agree_to_just_can_continue_to_buy,Toast.LENGTH_SHORT).show();
							return;
						}
						Intent intent = new Intent();
						intent.putExtra("list_dltdto", ApplicationData.getInstance().getList_11x5dto());
						intent.putExtra("AllMoney", allMoney);
						intent.putExtra("bs", bs);
						intent.putExtra("LotID", lotID);
						intent.putExtra("IssueID", issueID);
						intent.putExtra("IssueName", issueName);
						intent.putExtra("PlayTypeId", playTypeId);
						intent.setClass(ElvYunDJListActivity.this, FaQiHeMaiActivity.class);
						ElvYunDJListActivity.this.startActivityForResult(intent, REQ_CODE_BUYMAIN);
					}
				} else {
					Intent intent = new Intent();
					intent.setClass(context, LoginActivity.class);
					startActivity(intent);
				}
			}
		});
		
		zhuihao_EditText = (EditText) findViewById(R.id.buy_ssqxhlb_zhuihao);
		zhuihao_EditText.addTextChangedListener(zhuihaoWatcher);
		buy_11x5xhlb_EditText01 = (EditText) findViewById(R.id.buy_11x5xhlb_EditText01);
		moneyText = (TextView) findViewById(R.id.buy_11x5_money);
		/*
		 * 追号的焦点事件
		 */
		zhuihao_EditText.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					if (zh > 1) {
						gpc_hide.setVisibility(View.VISIBLE);
					}
				} else {
					if (gpc_hide.VISIBLE == View.VISIBLE) {
						gpc_hide.setVisibility(View.GONE);
					}
				}

			}
		});
		initText();
		initButton();
		titleBar();

		LinearLayout showOrHideLayout = (LinearLayout) findViewById(R.id.ll_show_hide);
		// IssueID 幸运选号 ""
//		int isFromLucky = getIntent().getIntExtra("isfromlucky", 0);
//		if (isFromLucky == 1) {
//			showOrHideLayout.setVisibility(View.GONE);
//			findViewById(R.id.rlzhuihao).setVisibility(View.INVISIBLE);
//		} else {
//			showOrHideLayout.setVisibility(View.VISIBLE);
//			// findViewById(R.id.rlzhuihao).setVisibility(View.VISIBLE);
//		}
		iszhuihao = (CheckBox) findViewById(R.id.iszhuihao);
	}

	public void initText() {
		// bsText = (TextView) findViewById(R.id.buy_11x5_list_bs);

		// sumBsText = (TextView) findViewById(R.id.buy_11x5_bs);
		// countText = (TextView) findViewById(R.id.buy_11x5_count);

		buy_11x5xhlb_EditText01.setText("1");
		// countText.setText("0");
		moneyText.setText("0");
		zhuihao_EditText.setText("1");
		// sumBsText.setText("1");
	}

	public void initButton() {
		btnAddRandom = (LinearLayout) findViewById(R.id.buy_11x5_list_addrandom);
		btnBack = (LinearLayout) findViewById(R.id.buy_11x5_list_back);
		btnClear = (LinearLayout) findViewById(R.id.buy_11x5_list_clear);
		// btnPlus = (Button) findViewById(R.id.buy_11x5_list_plus);
		// btnMinus = (Button) findViewById(R.id.buy_11x5_list_minus);
		btnBuy = (Button) findViewById(R.id.buy_11x5_buy);

		btnIntelligenceChase = (Button) findViewById(R.id.btn_intelligence_chase);
	}

	// 计算注数和金额
	public void FactoryAllResult() {
		// 计算注数和金额
		int money = 0;
		for (int i = 0; i < money_dintInt.getSize(); i++) {
			money = money + money_dintInt.getInt(i);
		}
		allMoney = money;
		// bs = Integer.parseInt(buy_11x5xhlb_EditText01.getText().toString());
		ApplicationData.getInstance().setAll_11x5money(allMoney);
		// countText.setText(money / 2 + "");
		moneyText.setText(money * bs * zh + "");
	}

	// TitleBar标题栏
	public void titleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});

		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText(R.string.buy_11ydjlist);

		Button refres = (Button) findViewById(R.id.top_title_refres);
		refres.getBackground().setAlpha(255);
		refres.setVisibility(View.INVISIBLE);
		// refres.setBackgroundResource(R.drawable.default_menu);
		// refres.setVisibility(View.VISIBLE);
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		});
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (ApplicationData.getInstance().getList_11x5dto().size() != 0) {
				MyDialog.Builder dialog = new MyDialog.Builder(context);
				dialog.setTitle("退出提示");
				dialog.setMessage("是否清除本次选号?");
				dialog.setPositiveButton("清除",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								clearPUtil();

								// 获得自定义的应用程序BallDTO,初始化
								ApplicationData.getInstance().initList();
								dialog.cancel();
								finish();
							}
						});
				dialog.setNegativeButton("保存",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								clearPUtil();
								int size = ApplicationData.getInstance()
										.getList_11x5dto().size();
								pUtil.putInt("eydu_size", size);
								for (int i = 0; i < size; i++) {
									pUtil.putString("eydu_ball" + i,
											ApplicationData.getInstance()
													.getList_11x5dto().get(i)
													.getElv_ball());
								}
								pUtil.putInt("eydu_allMoney", ApplicationData
										.getInstance().getAll_11x5money());
								pUtil.putInt("eydu_play", playTypeId);
								pUtil.putInt("eydu_prizeIntellChase",
										prizeIntellChase);
								ApplicationData.getInstance().initList();
								dialog.cancel();
								finish();
								Toast.makeText(context,
										R.string.design_change_saved,
										Toast.LENGTH_SHORT).show();
							}
						}).create().show();
			} else {
				// 无对话框退出
				clearPUtil();
				ApplicationData.getInstance().initList();
				finish();
			}
		} else {
			return super.onKeyDown(keyCode, event);
		}
		return true;
	}

	// 清除保存的号码记录
	public void clearPUtil() {
		int size = pUtil.getInt("eydu_size", 0);
		if (size != 0) {
			for (int i = 0; i < size; i++) {
				pUtil.remove("eydu_ball" + i);
			}
			pUtil.remove("eydu_size");
			pUtil.remove("eydu_allMoney");
			pUtil.remove("eydu_play");
			pUtil.remove("eydu_prizeIntellChase");
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 1001 && resultCode == RESULT_OK) {
			finish();
		}
		if (Constants.ZNZH_RES_CODE == resultCode) {
			issueName = data.getExtras().getString("issueName");
			Log.d("van", "-----十一运夺金---" + "---" + issueName);
		}
		if (resultCode == RESULT_OK) {
			if (requestCode == DefConstants.REQ_CODE_NO_MONEY_2_RECHARGE) {
				finish();
			}
		}
	}
}